home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dspgroup / mac320.arc / OFFLOAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-02-24  |  1.8 KB  |  110 lines

  1. /*THIS C PROGRAM PROVIDES A SKELETON FOR YOUR SPECIAL PURPOSE
  2. PROGRAM WHICH OPENS AN INTEL HEX FILE, AND BREAKS IT INTO ITS
  3. COMPONENT PARTS*/
  4.  
  5. #include "stdio.h"
  6. #define ERROR -1
  7. #define ENDFILE 0xff
  8. char infile[15];
  9. int infd,chsum,loadadd,nbytes;
  10.  
  11. main(argc,argv)
  12. int argc;
  13. char *argv[];
  14. {
  15. int i;
  16. int last;
  17.  
  18. if(argc!=2){
  19.     printf("\nCalling Sequence:\nOFFLOAD filespec\n");
  20.     exit(1);
  21.     }
  22. move(argv[1]);
  23. if((infd=open(infile,0))==ERROR){
  24.     printf("\nCannot Open:%s\n",infile);
  25.     exit(1);
  26.     }
  27. READ:chsum=0;
  28. while(inbyte()!=':');
  29. if((nbytes=hexb())==0)goto QUIT;
  30. /*
  31. printf("nbytes=%d\n",nbytes);
  32. */
  33. loadadd=(hexb()<<8)+hexb();
  34. /*
  35. printf("loadadd=%04x\n",loadadd);
  36. */
  37. hexb();
  38. for(i=0;i<nbytes;++i) oput(hexb());
  39. last=hexb();
  40. if(chsum&0xff){
  41. /*
  42.     printf("i=%02x last=%02x chsum=%02x\n",i,last,chsum);
  43. */
  44.     printf("\nRead Error\n");
  45.     exit(1);
  46.     }
  47. goto READ;
  48. QUIT:printf("\nLast Load Address:%04x\n",loadadd);
  49.  
  50. }
  51. move(string)
  52. char string[];
  53. {
  54. int i;
  55. char c;
  56.  
  57. for(i=0;(c=string[i])&&c!='.';++i) infile[i]=c;
  58. infile[i]='\0';
  59. strcat(infile,".HEX");
  60. }
  61. inbyte()
  62. {
  63. char c;
  64. while((c=getc(infd))=="\r"||c=='\n');
  65. /*
  66. putchar(c);
  67. */
  68. if(c==ENDFILE){
  69.     printf("\nUnexpected End of File\n");
  70.     exit(1);
  71.     }
  72. return(c);
  73. }
  74. hexc()
  75. {
  76. /*
  77. int tem;
  78. tem=dumm();
  79. printf("%02x",tem);
  80. return(tem);
  81. }
  82. dumm()
  83. {
  84. */
  85. char c;
  86.  
  87. c=inbyte();
  88. if((c>='0'&&c<='9')||(c>='A'&&c<='F'))
  89.     return(c<='9'?c-'0':c-'7');
  90. printf("\nRead Error in Hex File\n");
  91. exit(1);
  92. }
  93. hexb()
  94. {
  95. int v;
  96.  
  97. v=(hexc()<<4)+hexc();
  98. /*
  99. printf("hexb=%02x\n",v);
  100. */
  101. chsum=chsum-v;
  102. return(v);
  103. }
  104. oput(v)
  105. int v;
  106. {
  107. printf("@%04x=%02x\n",loadadd,v);
  108. ++loadadd;
  109. }
  110.